using System.Collections.Generic;
using Kotonoha.Server.Objects.Model;
using NHibernate;
using System.Linq;
using NHibernate.Linq;

namespace Kotonoha.Server.Db.Dao {
    public class ModelDao : DaoBase {
        public ModelDao(ISession session) : base(session) {}

        public bool existKanji(string ch) {
            return  (from s in session.Linq<Kanji>() where s.Character == ch select s).Count() != 0;
        }

        public List<Kanji> findAllKanji(ICollection<string> chs) {
            IQuery q = session.CreateQuery(
                    "from Kanji k join fetch k.Onyomis join fetch k.Kunyomis " + 
                    "join fetch k.Meanings where k.Character in (:col) group by k");
            q.SetParameterList("col",  chs.ToList());
            return q.List<Kanji>().ToList();
        }
    }
}